package com.chudian.controller;

import com.chudian.entity.Product;
import com.chudian.service.ProductService;
import com.chudian.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author : ZhangCheng
 * @date Date : 2022年10月25日
 */
@CrossOrigin //跨域
@Api(tags="商品管理") //用在类上
@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation("测试接口") //用在方法上
    @GetMapping("/test")
    public R test(){
        return R.ok() .data("message", "hello") .data("now", new Date());
    }

    @ApiOperation("商品列表") //用在方法上
    @GetMapping("/list")
    public R list(){
        List<Product> list = productService.list();
        return R.ok().data("productList",list);
    }
}
